< previous page page_407 next page >

Page 407
            txtData.BackColor = MDIParent.cdlg.Color
        Case 2 'Forecolor . . .
            txtData.ForeColor = MDIParent.cdlg.Color
    End Select
End Sub
'*********************************************************************
' If you set your indexes of your Window menu properly, you can save
' yourself some code. I was careful to make sure my Window menu items
' indices were equivalent to the possible values for the Arrange
' method.
'*********************************************************************
Private Sub mnuWindowItems_Click(Index As Integer)
    MDIParent.Arrange Index
End Sub
The first menu is the File menu, which is identical to the parent form, so you simply call the mnuFileItems_Click event in the parent for default processing. The second menu is the Options menu, which only appears in the child form, so you write your implementation code here. However, you make this event handler public so it could be accessed by your Toolbar control, which resides on the parent form. In addition, you use the CommonDialog control on the parent for your code, which displays the color dialog box.
tip.gif
If any menu item on your child form requires greater than 12 lines or so of code (excluding Dims, comments, and white space), you should move that code to a shared module or into the parent form. That prevents this code from consuming too much free memory every time a new form is added.

Finally, you have your Window menu that only applies to child forms (although it is the parent form that is responsible for this menu). By carefully creating your menu control array indices, you are able to write the implementation code for this menu using only one line of code.
Web.gif
ON THE WEB
From the Macmillan Web site, you can download another complete project that makes full use of the MDI concepts covered in this chapter. A text editor application named MDI Text Editor, it is similar in functionality to Windows Notepad, but it allows for multiple document windows to be open simultaneously. You can open this project from within Visual Basic; comments throughout the code explain how it works.

From Here . . .
This chapter provided you with an introduction to creating MDI applications using Visual Basic. For more information about some of the related topics covered in this chapter, see the following chapters:
To learn more about setting up forms, see Chapter 3, ''Visual Basic Building Blocks."
To learn more about creating database programs like the example in this chapter, see Chapter 26, "Using Data Access Objects (DAO)."

 
< previous page page_407 next page >